import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },
//疫情信息路由
{
  path: '/information',
  component: Layout,
  name: 'information',
  meta: { title: '疫情信息', icon: 'chart' },
  children: [
    {
      path: 'realtime',
      name: 'realtime',
      component: () => import('@/pages/information/realtime'),
      meta: { title: '实时疫情'}
    },
    {
      path: 'layout',
      name: 'layout',
      component: () => import('@/pages/information/layout'),
      meta: { title: '疫情动态'}
    },
    {
      path: 'map',
      name: 'map',
      component: () => import('@/pages/information/map'),
      meta: { title: '疫情地图'}
    }
  ]
},
//新闻资讯路由
  {
    path: '/news',
    component: Layout,
    name: 'news',
    meta: { title: '新闻资讯', icon: 'eye-open' },
    children: [
      {
        path: 'article',
        name: 'article',
        component: () => import('@/pages/news/article'),
        meta: { title: '最新资讯'}
      },
      {
        path: 'track',
        name: 'track',
        component: () => import('@/pages/news/track'),
        meta: { title: '病患轨迹'}
      },
      {
        path: 'refute',
        name: 'refute',
        component: () => import('@/pages/news/refute'),
        meta: { title: '资讯管理'}
      },
      {
        path: 'category',
        name: 'category',
        component: () => import('@/pages/news/Category'),
        hidden:true
      }
    ]
  },
  //定点医院路由
  {
    path: '/hospital',
    component: Layout,
    name:'hospital',
    meta: { title: '定点医院', icon: 'hospital' },
    children: [
      {//医院列表
        path:"index",
        component: () => import('@/pages/hospital/hospital'),
        meta:{title: '定点医院'}
      },
      { //医院地图
        path:"map",
        component: () => import('@/pages/hospital/hospitalmap'),
        hidden:true,
      }
      ,
      { //医院地图
        path:"map2",
        component: () => import('@/pages/hospital/hospitalmap2'),
        hidden:true,
      }
      ,
      { //医院地图
        path:"map3",
        component: () => import('@/pages/hospital/hospitalmap3'),
        hidden:true,
      }
      ,
      { //医院地图
        path:"map4",
        component: () => import('@/pages/hospital/hospitalmap4'),
        hidden:true,
      }
      ,
      { //医院地图
        path:"map5",
        component: () => import('@/pages/hospital/hospitalmap5'),
        hidden:true,
      }
      ,
      { //医院地图
        path:"map6",
        component: () => import('@/pages/hospital/hospitalmap6'),
        hidden:true,
      }
    ]
  },
  //基础配置路由
  {
    path: '/base',
    component: Layout,
    name: 'base',
    meta: { title: '基础配置', icon: 'example' },
    children: [
      {
        path: 'user',
        name: 'user',
        component: () => import('@/pages/base/user'),
        meta: { title: '用户管理'}
      },
      {
        path: 'role',
        name: 'role',
        component: () => import('@/pages/base/role'),
        meta: { title: '角色管理'}
      },
      {
        path: 'privilege',
        name: 'privilege',
        component: () => import('@/pages/base/privilege'),
        meta: { title: '权限设置'}
      }
    ]
  },
 

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
